<?php
require('config.php');

        $text=$_REQUEST['text'];
        $pai=$_REQUEST['pai'];
        $pinpai=$_REQUEST['pinpai'];
        $money_stat=$_REQUEST['money_stat'];
        $money_end=$_REQUEST['money_end'];
		$sql="select * from `".$oto."_goods` where goodsFlag='1' and isSale='1' and goodsStatus='1' and goodsStock>0 and `goodsName` LIKE '%$text%' ";
		if($pai='shaixuan')
		{
			if($pinpai!=0) $sql.=" and brandId='$pinpai'";
			if($money_end!=0) $sql.=" and shopPrice<='$money_end' and shopPrice>='$money_stat' ";
		}
		if($pai=='xiaoliang')
		{
			$sql.='order by `saleCount` DESC';
		}
		if($pai=='remen')
		{
			$sql.='order by `isHot` DESC';
		}
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$goods_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($goods_info))
		{
			$time_star=time();
			$time_end=$time_star-3600*24*30;
			$time_star1=date('Y-m-d H:i:s',$time_end);
			$time_end1=date('Y-m-d H:i:s',$time_star);
			for($j=0;$j<count($goods_info);$j++)
			{
				$goods_id=$goods_info[$j]['goodsId'];
				$sql="select * from `".$oto."_orders`,`".$oto."_order_goods` where ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_order_goods.goodsId='{$goods_id}' and createTime>='$time_star1' and createTime<='$time_end1' and orderStatus='4'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$order_list[$j][]=$row;//将取得的所有数据赋值给person_info数组
				}
				$sum=0;
				if(isset($order_list[$j]))
				{
					for($i=0;$i<count($order_list[$j]);$i++)
					{
						$sum+=$order_list[$j][$i]['goodsNums'];
					}
				}
				$goods_info[$j]['yue_xiaoliang']=$sum;
			}
		}
		echo json_encode($goods_info);
?>